define(["jquery","bbcare","fu/app/comm/comm"],function($,$bb,$comm){
    var servers = {};
    var URL = $bb.baseUrl("followup");

    /**
     * 请求患者应用列表统计数据
     */
    servers.ajaxPatientStatistics = function(callback){
        $bb.ajax({
            url: URL + "followup/service/nutrition/patientscheme/statistics",
            success: function(data){
                if(data.success){
                    callback(data.data);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "请求患者应用列表统计数据出错！");
                }
            }
        });
    }
    
    /**
     * 请求患者营养方案列表
     */
    servers.ajaxList = function(params,callback){
        $bb.ajax({
            url: URL + "followup/service/nutrition/patientscheme/list",
            data: JSON.stringify({
                data: params
            }),
            success: function(data){
                if(data.success){
                    callback(data,params);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "请求患者营养方案列表出错！");
                }
            }
        });
    };

    /**
     * 处理获取到的营养方案列表数据
     */
    servers.handleList = function(list,rows){
        var fillSpace = [];
        for (var i = 0; i < list.length; i++) {
            list[i].createTime = list[i].createTime.substr(0,10);
            list[i].stageWidth = (100 / list[i].stageNums - 1) + "%";
            list[i].stageMarginWidth = (100 / list[i].stageNums - 1) * (list[i].currentStageNum - 1) + "%";
            list[i].stageArr = [];
            for (var j = 0; j < list[i].stageNums; j++) {
                list[i].stageArr[j] = list[i].currentStageNum - 1 == j ? 1 : 0;
            }
        }
        if( rows - list.length > 0 ){
            for (var i = 0; i < rows - list.length; i++) {
                fillSpace.push({});
            } 
        }
        return {"list":list,"fillSpace":fillSpace};
    }

    return servers;
});